/* 
 * File:   SaveLabelImage.cpp
 * Author: hadrien
 * 
 * Created on 21 avril 2012, 16:04
 */

#include "SaveLabelImage.h"
using namespace cv;

SaveLabelImage::SaveLabelImage() {
}

SaveLabelImage::SaveLabelImage(const SaveLabelImage& orig) {
}

SaveLabelImage::~SaveLabelImage() {
}

void SaveLabelImage::saveImage(int** labels, int height, int width, int nb_label, char* imgName) {
    IplImage* segmented = cvCreateImage(cvSize(width, height), 8, 1);
    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++) {
            char label = (255 * labels[x][y]) / nb_label;
            CV_IMAGE_ELEM(segmented, uchar, y, x) = label;
        }
    cvSaveImage(imgName, segmented);
    cvReleaseImage(&segmented);
}
